import React, { useState, useEffect } from 'react';
import { Table, Card, Form, Input, Select, Button, Space, Tag, Popconfirm, message } from 'antd';
import { useNavigate } from 'react-router-dom';
import { PlusOutlined, EditOutlined, DeleteOutlined, TeamOutlined } from '@ant-design/icons';
import { contestService } from '@/services/contestService';
import { Contest, ContestRuleType, ContestStatus, ContestType } from '@/types/contest';
import styles from './List.module.css';
import dayjs from 'dayjs';
import ContestListShared from '@/pages/share/contest/List';

const { Option } = Select;

const AdminContestList: React.FC = () => {
  const navigate = useNavigate();

  const handleDelete = async (id: number) => {
    try {
      await contestService.deleteContest(id);
      message.success('删除成功');
    } catch (error) {
      message.error('删除失败');
    }
  };

  const columns = [
    {
      title: '操作',
      key: 'action',
      width: 300,
      render: (_: any, record: Contest) => (
        <Space>
          <Button 
            type="link" 
            onClick={() => navigate(`/admin/contest/${record.id}`)}
          >
            详情
          </Button>
          <Button 
            type="link" 
            onClick={() => navigate(`/admin/contest/${record.id}/problems`)}
          >
            题目
          </Button>
          <Button 
            type="link" 
            onClick={() => navigate(`/admin/contest/${record.id}/announcements`)}
          >
            公告
          </Button>
          <Button 
            type="link" 
            onClick={() => navigate(`/admin/contest/edit/${record.id}`)}
          >
            编辑
          </Button>
          <Button 
            type="link" 
            danger 
            onClick={() => handleDelete(record.id)}
          >
            删除
          </Button>
        </Space>
      ),
    },
  ];

  return <ContestListShared isAdmin={true} />;
};

export default AdminContestList; 